// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import "babel-polyfill";
// import 'es6-promise/auto'
// import promise from 'es6-promise';
// promise.polyfill();

import Vue from "vue";
import App from "./App";
import store from "./store";
import router from "./router";

//引入rem适配
import "@/assets/js/flexible.js";
Vue.config.productionTip = false;
//  判断设置类型
Vue.prototype.$isMobile = function isMobile() {
  if (
    window.navigator.userAgent.match(
      /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
    )
  ) {
    return true; // 移动端
  } else {
    return false; // PC端
  }
};
Vue.prototype.$pxToRem = function pxToRem(content) {
    if (!content) return;
    let reg = /([:|(]*)(\s*)([-|+\d+.*\d+]+)(px)/g;
    let str = content.replace(reg, (content, $1, space, $2) => {
      return $1 + space + parseInt($2) / 100 + "rem";
    });
    let regSpace = /(>)(\s)+(<)/g;
    str = str.replace(regSpace, (content, $1, space, $2) => {
      return $1 + $2;
    });
    return str;
  };
// import vueSwiper from 'vue-awesome-swiper'  //引入vue-awesome-swiper
// // import 'swiper/dist/css/swiper.css'  //引入样式
// import 'swiper/css/swiper.min.css'
// Vue.use(vueSwiper)  //使用插件

import VueAwesomeSwiper from "vue-awesome-swiper";

// import style  import 'node_modules/vue-awesome-swiper/node_modules/swiper/dist/css/swiper.css'
import "swiper/dist/css/swiper.css";

Vue.use(VueAwesomeSwiper);

router.beforeEach((to, from, next) => {
  if (to.meta.parameter) {
    if (!to.query.id) {
      next({
        name: "zh_home"
      });
    }
  }
  if (to.matched.length == 0) {
    let name = to.name;
    if (!name) {
      next({ name: "zh_home" });
    }
    if (name.indexOf("zh_") != -1) {
      next({ name: "zh_home" });
    } else if (name.indexOf("en_") != -1) {
      next({ name: "en_home" });
    } else if (name.indexOf("jap_") != -1) {
      next({ name: "jap_home" });
    }
  }
  next();
});

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI);

import "@/assets/directives/flex_for";

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  store,
  components: { App },
  template: "<App/>"
});
